import {Component} from 'react'

export default class Parent extends Component{
    state = {
        childMsg:"child msg before"
    }
    changeChildMsg = () => {
        this.setState({childMsg:"child msg after"})
    }
    render(){
        return (
            <>
            <h2>父组件</h2>
            <button onClick={this.changeChildMsg}>修改传值</button>
            <Child childMsg={this.state.childMsg}/>
            </>
        )
    }
}


class Child extends Component{
    render(){
        const {childMsg} = this.props
        return (
            <>
            <h2>子组件</h2>
            <div>{childMsg}</div>
            </>
        )
    }
}